<template>
	<view>
		<view class="navbar" :style="{
			paddingTop:`${statusBarHeight + 2}px`
		}">
			<view class="icon" @click="routeBack">
				<u-icon name="arrow-left" size="32rpx" color="#FFFFFF"></u-icon>
			</view>
			<view class="item" :class="[
				navBarCr===item&&'active'
			]" v-for="(item,index) in navBarList" :key="index" @click="navBarCr = item">{{item}}</view>
		</view>
		<view class="banner">
			<u-swiper height='750rpx' :list="detail.storeInfo.sliderImageArr" :autoplay="false"></u-swiper>
		</view>
		<view class="details">
			<view class="priceAndOperation">
				<view class="price">
					<text style="font-size: 24rpx;">￥</text>{{detail.storeInfo.price}}
				</view>
				<view>
					<image class="wh48" src="https://test.uaima.cn/public/static/img/mine/8.png"></image>
					<image class="wh48" style="margin-left: 30rpx;" src="https://test.uaima.cn/public/static/img/mine/10.png"></image>
				</view>
			</view>
			<view class="title pd0_30">
				{{detail.storeInfo.storeName}}
			</view>
			<view class="sell pd0_30">
				已售{{detail.storeInfo.sales}}
			</view>
			<view class="profile">
				<view class="item">
					<view>毛重</view>
					<view>约{{detail.storeInfo.grossWeight}}斤</view>
				</view>
				<view class="line"></view>
				<view class="item">
					<view>毛单价</view>
					<view>约{{detail.storeInfo.grossPrice}}斤</view>
				</view>
				<view class="line"></view>
				<view class="item">
					<view>净重</view>
					<view>约{{detail.storeInfo.netWeight}}斤</view>
				</view>
				<view class="line"></view>
				<view class="item">
					<view>净单价</view>
					<view>约{{detail.storeInfo.netPrice}}斤</view>
				</view>
			</view>
			<u-gap height="30rpx"></u-gap>
			<u-gap height="16rpx" bgColor="#F5F5F5"></u-gap>
		</view>
		<view class="productSpecification">
			<view class="productModuleTitle pd0_30">
				<view></view>
				<view>产品规格</view>
			</view>
			<view class="main">
				<view class="minItem">
					<view class="title">等级</view>
					<view class="value">{{detail.storeInfo.level}}</view>
				</view>
				<view class="minItem borderLeft">
					<view class="title">产地</view>
					<view class="value">{{detail.storeInfo.placeOfOrigin}}</view>
				</view>
				<view class="minItem borderTop">
					<view class="title">不良率</view>
					<view class="value">{{detail.storeInfo.defectRate}}</view>
				</view>
				<view class="minItem borderLeft borderTop">
					<view class="title">包装层数</view>
					<view class="value">{{detail.storeInfo.numberOfPackagingLayers}}</view>
				</view>
				<view class="minItem borderTop">
					<view class="title">货源</view>
					<view class="value">{{detail.storeInfo.sourceOfGoods}}</view>
				</view>
				<view class="minItem borderLeft borderTop">
					<view class="title">规格</view>
					<view class="value">约{{detail.storeInfo.grossWeight}}斤</view>
				</view>
				<view class="maxItem  borderTop">
					<view class="title">保存条件</view>
					<view class="value">{{detail.storeInfo.storageConditions}}</view>
				</view>
				<view class="maxItem  borderTop">
					<view class="title">商品描述</view>
					<view class="value">{{detail.storeInfo.storeInfo}}</view>
				</view>
			</view>
			<u-gap height="30rpx"></u-gap>
			<u-gap height="16rpx" bgColor="#F5F5F5"></u-gap>
		</view>
		<view class="After-salesInstructions">
			<view class="productModuleTitle pd0_30">
				<view></view>
				<view>售后说明</view>
			</view>
			<view class="content pd0_30">
				收货检查：请在收到火龙果后，第一时间检查包装是否完好，以及火龙果的外观是否新鲜、无破损。
				及时联系：如发现包装破损、火龙果有腐烂、变质等情况，请立即拍照并联系我们的客服团队，以便我们及时处理。
			</view>
		</view>
		<u-gap height="30rpx"></u-gap>
		<u-gap height="16rpx" bgColor="#F5F5F5"></u-gap>
		<view class="prodcutDetails">
			<view class="productModuleTitle pd0_30">
				<view></view>
				<view>商品详情</view>
			</view>
			<view class="pd0_30" style="margin-top: 30rpx;">
				<u-parse :content="detail.storeInfo.description"></u-parse>
			</view>
		</view>
		<u-gap height="260rpx"></u-gap>
		<view class="foot">
			<view class="left">
				<view class="item" style="margin-right: 60rpx;" @click="route_type">
					<image class="wh44" src="https://test.uaima.cn/public/static/img/mine/11.png"></image>
					<view>分类</view>
				</view>
				<view class="item" @click="appendCard">
					<image class="wh44" src="https://test.uaima.cn/public/static/img/mine/12.png"></image>
					<view>购物车</view>
				</view>
			</view>
			<view class="payBtn" @click="confirmOrder">立即购买</view>
		</view>
	</view>
</template>

<script>
	import msg from "@/utils/msg.js"
	export default {
		data() {
			return {
				statusBarHeight: 0,
				navBarList: ['商品', '规格', '售后', '详情'],
				navBarCr: '商品',
				detail: {},
				swiper: [{
					url: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
					title: '身无彩凤双飞翼，心有灵犀一点通'
				}],
				content: `
									<p>露从今夜白，月是故乡明</p>
									<img src="https://cdn.uviewui.com/uview/swiper/2.jpg" />
								`,
				id: ""
			};
		},
		onLoad(option) {
			this.id = option.id
			this.productsDetail()
			this.statusBarHeight = uni.$statusBarHeight;
		},
		methods: {
			appendCard() {
				let firstKey = Object.keys(this.detail.productValue)[0]; 
				let firstProduct = this.detail.productValue[firstKey];
				this.$iApi.cartAdd({
					cartNum: this.detail.storeInfo.id,
					productId: this.detail.storeInfo.id,
					uniqueId: firstProduct.unique,
				}).then(res => {
					msg.toast("已加入购物车");
				})
			},
			productsDetail() {
				this.$iApi.productsDetail(this.id).then(res => {
					this.detail = res.data
				})
			},
			routeBack() {
				uni.navigateBack()
			},
			route_type() {
				uni.switchTab({
					url: "/pages/classify/index"
				})
			},
			confirmOrder() {
				uni.navigateTo({
					url: "/pages/product/confirmOrder" + `?type=2&id=${this.id}`
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.navbar {
		position: fixed;
		left: 0;
		top: 0;
		width: 100vw;
		height: 64rpx;
		z-index: 2;
		display: flex;
		align-items: center;

		.icon {
			padding-top: 6rpx;
			margin-left: 30rpx;
			margin-right: 70rpx;
		}

		.item {
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			transition: all 300ms;
			margin-right: 30rpx;
			opacity: .8;
		}

		.active {
			font-weight: 400;
			font-size: 36rpx;
			color: #FFFFFF;
			position: relative;
			opacity: 1;

			&:before {
				content: "";
				display: block;
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
				bottom: -8rpx;
				width: 18rpx;
				height: 6rpx;
				background: #FFFFFF;
				border-radius: 19rpx 19rpx 19rpx 19rpx;
			}
		}
	}

	.wh48 {
		width: 48rpx;
		height: 48rpx;
	}

	.wh44 {
		width: 44rpx;
		height: 44rpx;
	}

	.pd0_30 {
		padding: 0 30rpx;
	}

	.banner {
		height: 690rpx;
	}

	.details {
		position: relative;
		z-index: 1;
		background-color: #fff;
		border-radius: 40rpx 40rpx 0 0;

		.priceAndOperation {
			padding: 33rpx 30rpx 0;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.price {
				font-weight: 600;
				font-size: 32rpx;
				color: #ED7B42;
			}
		}

		.title {
			font-weight: 400;
			font-size: 32rpx;
			color: #333333;
			line-height: 42rpx;
			margin-top: 31rpx;
		}

		.sell {
			font-weight: 400;
			font-size: 26rpx;
			color: #999999;
			line-height: 42rpx;
			margin-top: 8rpx;
		}

		.profile {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 690rpx;
			height: 140rpx;
			background: #F5F5F5;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin: 20rpx auto 0;

			.line {
				width: 1rpx;
				height: 57rpx;
				background: #999999;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				opacity: 0.5;
				// margin: 0 36rpx;
			}

			.item {
				width: 25%;
				text-align: center;

				view:first-child {
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
				}

				view:last-child {
					font-weight: 400;
					font-size: 26rpx;
					color: #ED7B42;
					margin-top: 10rpx;
				}
			}
		}
	}

	.productModuleTitle {
		display: flex;
		align-items: center;
		margin-top: 30rpx;

		view:first-child {
			width: 6rpx;
			height: 28rpx;
			background: #28BA54;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			margin-right: 16rpx;
		}

		view:last-child {
			font-weight: 500;
			font-size: 36rpx;
			color: #333333;
		}
	}

	.productSpecification {
		.main {
			width: 690rpx;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			border: 1rpx solid #CCCCCC;
			display: flex;
			flex-wrap: wrap;
			margin: 30rpx auto 0;

			.borderLeft {
				border-left: 2rpx solid #D9D9D9;
			}

			.borderTop {
				border-top: 2rpx solid #D9D9D9;
			}

			.title {
				font-weight: 400;
				font-size: 30rpx;
				color: #666666;
				margin-left: 30rpx;
				margin-right: 60rpx;
			}

			.value {
				font-weight: 400;
				font-size: 30rpx;
				color: #151515;
			}

			.minItem {
				width: 345rpx;
				height: 99rpx;
				line-height: 99rpx;
				display: flex;
			}

			.maxItem {
				width: inherit;
				height: 99rpx;
				line-height: 99rpx;
				display: flex;
			}
		}
	}

	.After-salesInstructions .content {
		font-weight: 400;
		font-size: 28rpx;
		color: #333333;
		line-height: 48rpx;
		margin-top: 30rpx;
	}

	.foot {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100vw;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 17rpx 30rpx;
		box-sizing: border-box;
		padding-bottom: constant(safe-area-inset-bottom); //兼容IOS<11.2
		padding-bottom: env(safe-area-inset-bottom); //兼容 I0S>11.2

		.left {
			display: flex;
			align-items: center;

			.item {
				text-align: center;

				view {
					font-weight: 400;
					font-size: 22rpx;
					color: #333333;
					margin-top: 11rpx;
				}
			}
		}

		.payBtn {
			text-align: center;
			width: 400rpx;
			height: 72rpx;
			line-height: 72rpx;
			background: #67B609;
			border-radius: 100rpx 100rpx 100rpx 100rpx;
			font-weight: 400;
			font-size: 22rpx;
			color: #FFFFFF;
		}
	}
</style>